package com.medical.data.controller;


import com.medical.data.domain.Department;
import com.medical.data.domain.User;
import com.medical.data.service.DepartmentService;
import com.medical.data.utils.Result;
import com.medical.data.vo.ProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cj
 * @since 2024-02-09
 */
@RestController
@RequestMapping("/data/department")
@Api(description = "科室管理")
@Slf4j
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("新增科室")
    @PostMapping("/addDepartment")
    public Result addDepartment(@Validated @RequestBody Department department) {
        log.info("/data/department/addDepartment参数========>{}", department);
        departmentService.addDepartment(department);
        return Result.ok();
    }

    @ApiOperation("获取所有科室")
    @PostMapping("/getDepartments/{hospitalId}")
    public Result getDepartments(@NotBlank(message = "医院id不可为空") @PathVariable("hospitalId") String hospitalId) {
        log.info("/data/department/getDepartments参数========>{}", hospitalId);
        List<Department> departments = departmentService.getDepartments(hospitalId);
        return Result.ok().data("departments", departments);
    }

    @ApiOperation("修改科室")
    @PostMapping("/updateDepartment")
    public Result updateDepartment(@Validated @RequestBody Department department) {
        log.info("/data/department/updateDepartment参数========>{}", department);
        departmentService.updateDepartment(department);
        return Result.ok();
    }

    @ApiOperation("查看科室详情")
    @PostMapping("/getDepartmentDetails/{departmentId}")
    public Result getDepartmentDetails(@NotBlank(message = "科室id不可为空") @PathVariable("departmentId") String departmentId) {
        log.info("/data/department/getDepartmentDetails参数========>{}", departmentId);
        Department department = departmentService.getById(departmentId);
        return Result.ok().data("department", department);
    }

    @ApiOperation("删除科室")
    @PostMapping("/deleteDepartment/{departmentId}")
    public Result deleteDepartment(@NotBlank(message = "科室id不可为空") @PathVariable("departmentId") String departmentId) {
        log.info("/data/department/deleteDepartment参数========>{}", departmentId);
        departmentService.removeById(departmentId);
        return Result.ok();
    }

    @ApiOperation("查看该科室下所有的医生")
    @PostMapping("/getUserByDepartmentId/{departmentId}")
    public Result getUserByDepartmentId(@NotBlank(message = "科室id不可为空") @PathVariable("departmentId") String departmentId) {
        log.info("/data/department/getUserByDepartmentId参数========>{}", departmentId);
        List<User> users = departmentService.getUserByDepartmentId(departmentId);
        return Result.ok().data("users", users);
    }

}

